#include "private_implementations/JsonArray.h"
#include "private_implementations/JsonObject.h"
#include "interfaces/types/JsonTypeDefs.h"
namespace simframework
{
	namespace json
	{

		Object::Object(std::wostream& js):m_jsonStream(js), m_isFirstElement(true)
		{
			m_jsonStream << json_start_of_object;
		}

		Object::Object( const Object& other ):m_jsonStream(other.m_jsonStream), m_isFirstElement(other.m_isFirstElement)
		{

		}
		Object::~Object()
		{
			m_jsonStream << json_end_of_object;
		}

		Object Object::startObject(const std::wstring& key)
		{		
			writeKey(key);
			return Object(m_jsonStream);
		}

		Array Object::startArray(const std::wstring& key)
		{		
			writeKey(key);
			return Array(m_jsonStream);
		}	

		void Object::writeKey( const std::wstring& key )
		{
			if (m_isFirstElement)
			{
				m_isFirstElement = false;
			}
			else
			{
				m_jsonStream << json_element_seperator;				
			}			
			m_jsonStream << json_string_delimiter << key << json_string_delimiter << json_key_value_seperator;	
		}
	};
}